package com.kcyu.sfhinvoice.config;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.kcyu.sfhinvoice.domain.User;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class HeartbreakInterceptor implements HandlerInterceptor {

    private static final Log log = LogFactory.get();

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        if(request.getRequestURI().startsWith("/sys/")) {
            return HandlerInterceptor.super.preHandle(request, response, handler);
        }


        int loginIdAsInt = StpUtil.getLoginIdAsInt();
        String username = new User().selectById(loginIdAsInt).getUsername();
        log.info("用户{}，请求访问{}", username, request.getRequestURI());

        return HandlerInterceptor.super.preHandle(request, response, handler);
    }
}
